<TABLE CLASS="TABLEBG" CELLSPACING="0" CELLPADDING="0" WIDTH="100%" BORDER="0">
<!--
PlaceHolders used for getting details of user acts on for activity
<%#ActivityResourceIdentifier%>
<%#ActivityResourceName%>
<%#ActivityResourceEmail%>

PlaceHolders used for getting details of Loggedin Resources for activity
<%#ActivityLoggedInResourceIdentifier%>
<%#ActivityLoggedInResourceName%>
<%#ActivityLoggedInResourceEmail%>


-->
	<TR Class="N-MainBGColor">
		<TD class="heading2"  height=20>
			<!--<B>Search Activities :-->
		</TD>
	</TR>
	<TR>
		<TD>
			<TABLE CLASS="TABLEBG" CELLSPACING="1" HEIGHT="100%" CELLPADDING="3" WIDTH="100%" BORDER="0" ID="Table6">
				<TR class="N-ListBGCOLORCOL2">
					<TD WIDTH="15%" CLASS="runtext1">
						<!--Search By Saved<br>
						Search Criteria.-->
					</TD>
					<TD align="CENTER">
						<!--<SELECT name="selsavedsearch" class=select1 onchange="javascript:SetActivitySet(this.value,this.form)">
							<OPTION value="0">Select Saved Search</OPTION>
							<%#savedactivityset%>
						</SELECT>-->
						<%#ErrActivitySets%>
					</TD>
					<TD align="right" valign=bottom>
							<!--<table CELLSPACING="1" CELLPADDING="1" BORDER="0" ID="Table6" width=100%>
								<tr>
									<td>
										<IMG src="<%#VirtualDirectory%>/images/resource-calendar.gif" alt="Resource Calendar" style="cursor:hand" ONCLICK="OpenNewWin(1,2,0)">
									</td>
									<td>
										Resource Calendar
									</td>
									<td>
										<IMG src="<%#VirtualDirectory%>/images/alternate-resource.gif" alt="Alternate Resource" style="cursor:hand" ONCLICK="OpenNewWin(1,3,0)">
									</td>
									<td>
										Alternate Resource
									</td>
									<%#opencomment%>
									<td>
										<IMG src="<%#VirtualDirectory%>/images/personalize.gif" alt="Personalize" style="cursor:hand" ONCLICK="OpenNewWin(1,1,0)">
									</td>
									<td>
										Personalize
									</td><%#closecomment%>
									<td>
										<IMG src="<%#VirtualDirectory%>/images/refresh.gif" alt="Refresh" style="cursor:hand" ONCLICK="javascript:location.href=location.href">
									</td>
									<td>
										Refresh
									</td>
								</tr>
							</table>-->
						</TD>
						<!--&nbsp;&nbsp;
						<IMG src="<%#VirtualDirectory%>/images/resource-calendar.gif" alt="Resource Calendar" style="cursor:hand" ONCLICK="OpenNewWin(1,2,0)">
						&nbsp;&nbsp;
						<IMG src="<%#VirtualDirectory%>/images/alternate-resource.gif" alt="Alternate Resource" style="cursor:hand" ONCLICK="OpenNewWin(1,3,0)">
						&nbsp;&nbsp;
						<%#opencomment%><IMG src="<%#VirtualDirectory%>/images/personalize.gif" alt="Personalize" style="cursor:hand" ONCLICK="OpenNewWin(1,1,0)"><%#closecomment%>
						-->
					</TD>
				</TR>
			</TABLE>
		</TD>
	</TR>
	<TR bgcolor="AliceBlue">
		<TD class="heading2">
			<IMG src="<%#VirtualDirectory%>/images/spacer.gif" height="5"></TD>
	</TR>
	<TR>
		<TD>
			<TABLE CLASS="TABLEBG" CELLSPACING="1" HEIGHT="100%" CELLPADDING="3" WIDTH="100%" BORDER="0" ID="Table6">
				<TR class="N-ListBGCOLORCOL1">
					<TD CLASS="runtext1" width="25%">
						<B>Query On</B>
					</TD>
					<TD CLASS="runtext1" width="13%">
						<B>Operators</B>
					</TD>
					<TD CLASS="runtext1" width="13%">
						<B>Fields</B>
					</TD>
					<TD CLASS="runtext1" width="40%">
						<B>Value</B>
					</TD>
					<TD align="left" width="13%">
						<B>Condition</B>
					</TD>
				</TR>
				<TR class="N-ListBGCOLORCOL2">
					<TD CLASS="runtext1" width="25%">
						<SELECT name="selquery" id="selquery" class="select1" onchange="javascript:listoperators(this.value)">
							<OPTION value="0">Select Query Field</OPTION>
							<OPTION value="(">'('</OPTION>
							<%#queryfields%>
						</SELECT>
					</TD>
					<TD CLASS="runtext1" width="13%">
						<SELECT name="seloperator" id="seloperator" class="select1">
						</SELECT>
					</TD>
					<TD CLASS="runtext1" width="13%">
						<SELECT name="selvalue" id="selvalue" class="select1" onchange="ChangeInputField(this.value);">
						</SELECT>
					</TD>
					<TD CLASS="runtext1" width="40%">
						<div id="expr2">&nbsp;</div>
					</TD>
					<TD align="left" width="13%">
						<SELECT id="selcondition" name="selcondition" class="select1">
							<OPTION value="End" selected>End</OPTION>
							<OPTION value=" And ">And</OPTION>
							<OPTION value=" Or ">Or</OPTION>
							<OPTION value=") And ">')' And</OPTION>
							<OPTION value=") Or ">')' Or</OPTION>
						</SELECT>
					</TD>
				</TR>
				<TR class="N-ListBGCOLORCOL1">
					<TD colspan="5">
						<INPUT type="checkbox" value="" name="btnSaveSet" ID="Submit1" onclick="javascript:if(this.checked) {return SetName();}"> Save search.
						<INPUT type=hidden name="hiddenactivityset" value="">
						<IMG src="<%#VirtualDirectory%>/images/spacer.gif" height="1" width="450">
						<!--onclick="return Button1_onclick();"-->
						<INPUT id="button1" class="button2" type="submit" value=" Add " name="Button1" onclick="return Button1_onclick();">
						&nbsp;
						<!--onclick="return undo_onclick()"-->
						<INPUT id="undo" class="button2" type="button" value=" Undo " name="undo" onclick="return undo_onclick()">
						&nbsp;
						<!-- onclick="return Button2_onclick()"-->
						<INPUT id="button2" class="button2" type="button" value=" Clear " name="Button2" onclick="return Button2_onclick()">
					</TD>
				</TR>
			</TABLE>
		</TD>
	</TR>
	<TR bgcolor="AliceBlue">
		<TD class="heading2"><IMG src="<%#VirtualDirectory%>/images/spacer.gif" height="5"></TD>
	</TR>
	<TR>
		<TD width="100%" height=100% colspan=5>
			<TABLE CLASS="TABLEBG" CELLSPACING="1" CELLPADDING="2" WIDTH="100%" BORDER="0" ID="Table7">
				<TR CLASS="N-TopRowBG">
					<TD CLASS="runtext1" height="100">
						<table width="100%" ID="Table9" height="100%" bgcolor="#808080" cellspacing="1" border="0">
							<tr>
								<td bgcolor="#d4d0c8" width="15">&nbsp;</td>
								<td bgcolor="#d4d0c8" valign="middle" height="20">Show activity list where..</td>
							</tr>
							<tr>
								<TD bgcolor="#d4d0c8" width="15">&nbsp;</TD>
								<td valign="top" bgcolor="White">
									<div id="exprstr" name="exprstr">&nbsp;</div>
									<INPUT type=hidden name="displayquerybuildervaluehidden" value="">
									<INPUT type=hidden name="querybuildervaluehidden" value="">
									<INPUT type=hidden name="ResourcesExpression" value="">
									<INPUT type=hidden name="ResourcesDispExpression" value="">
								</td>
							</tr>
						</table>
					</TD>
				</TR>
			</TABLE>
		</TD>
	</TR>
</TABLE>
</TD></TR>
<TR align="center" valign="top" Class="N-MainBGColor">
	<TD COLSPAN="5" CLASS="RUNTEXT1">
		<TABLE BORDER="0" CELLSPACING="1" CELLPADDING="0" WIDTH="100%">
			<TR>
				<TD  WIDTH="40%" class="runtext1" align=right>
					<INPUT type=submit value="Search" class=button2 name="btnSearch" onclick="return SetDynamicValues()">
					<INPUT type=hidden name="datecorrectionfactor" value="">
					&nbsp;&nbsp;
					<!--<INPUT type=button value="Refresh" class=button2 name="btnRefresh" onclick="javascript:location.href=location.href">-->
				</TD>
				<TD WIDTH="60%">
					<%#HyperLink%>
				</TD>
			</TR>
		</TABLE>
	</TD>
</TR>
<!----Search Value -->
<SCRIPT>


	//Dynacmic drop downs
	var OperatorsArray = new Array();
	function Operators(QueryName, OperatorName,OperatorValue)
	{
		rExp = /@!@#/g
		ramp= /&amp;/g
		rlt= /&lt;/g
		rgt= /&gt;/g
		rquot=/&quot;/g
		this.QueryName = QueryName;
		this.OperatorName = OperatorName.replace(rExp,"'").replace(ramp,"&").replace(rlt,"<").replace(rgt,">")
		this.OperatorValue = OperatorName.replace(rExp,"'").replace(ramp,"&").replace(rlt,"<").replace(rgt,">");
	}
	//dynamic drop downs
	var FieldsArray = new Array();
	function Fields(QueryName, FieldName, FieldValue, WorkflowFlag,FieldMessage)
	{
		rExp = /@!@#/g
		ramp= /&amp;/g
		rlt= /&lt;/g
		rgt= /&gt;/g
		rquot=/&quot;/g
		this.QueryName = QueryName;
		this.FieldName   = FieldName.replace(rExp,"'").replace(ramp,"&").replace(rlt,"<").replace(rgt,">");
		this.FieldValue  = FieldValue.replace(rExp,"'").replace(ramp,"&").replace(rlt,"<").replace(rgt,">");
		this.WorkflowFlag = WorkflowFlag ;
		this.FieldMessage = FieldMessage.replace(rExp,"'").replace(ramp,"&").replace(rlt,"<").replace(rgt,">");
	}

	function listoperators(query)
	{
		if(query != '(')
		{
			operatorscount = document.getElementsByTagName("select")["seloperator"].length ;
			for(opt=0;opt<= operatorscount; opt++)
				{
					document.getElementsByTagName("select")["seloperator"].options[0]=null;
				}

			//alert(operatorleadflag)
			if (query != "" && typeof(query) != 'undefined')
				{
					obj = document.getElementsByTagName("select")["seloperator"] ;
					for (i=0;i<OperatorsArray.length;i++)
						{
							if ( OperatorsArray[i].QueryName == query)
								{
									f = new Option(OperatorsArray[i].OperatorName," "+ OperatorsArray[i].OperatorValue +" ",0,0);
									opcount = document.getElementsByTagName("select")["seloperator"].length ;
									eval("obj.options["+opcount+"]=f");
								}
						}
				}
				listfields(query);
		}
	}
	function listfields(query)
	{

		//Change the default display
		changeDiv('defaultdiv');

		fieldscount = document.getElementsByTagName("select")["selvalue"].length ;
		for(opt=0;opt<= fieldscount; opt++)
			{
				document.getElementsByTagName("select")["selvalue"].options[0]=null;
			}
		f = new Option('Select Field Type','defaultdiv',0,0);
		obj = document.getElementsByTagName("select")["selvalue"] ;
		eval("obj.options[0]=f");
		//alert(operatorleadflag)
		if (query != "" && typeof(query) != 'undefined')
			{
				obj = document.getElementsByTagName("select")["selvalue"] ;
				for (i=0;i<FieldsArray.length;i++)
					{
						if ( FieldsArray[i].QueryName == query)
							{
								f = new Option(FieldsArray[i].FieldName,FieldsArray[i].FieldValue+"#"+FieldsArray[i].FieldMessage,0,0);
								opcount = document.getElementsByTagName("select")["selvalue"].length ;
								eval("obj.options["+opcount+"]=f");
							}
					}
			}
	}
	function ChangeInputField(displaydiv)
	{
		changeDiv(displaydiv);

	}
	var oexpr2;

	oexpr2 = document.getElementsByTagName("div")["expr2"];
	function changeDiv( divvar )
	{
		if( !oexpr2 )
			oexpr2 = document.getElementsByTagName("div")["expr2"];
		//Display text messages along with value, message is appended to the select value with # as the seperator
		oexpr2.innerHTML = eval(((divvar.split("#"))[0])) +"<br><span id=messageDisp style='position:relative;face:verdana'></span>";
		//Show the message only if valid.
		if(typeof(((divvar.split("#"))[1])) != 'undefined' && typeof(((divvar.split("#"))[1])) != "")
			messageDisp.innerHTML = ((divvar.split("#"))[1])

	}
	function GetLoopValue(from,to,increment,selectval)
	{
		var string="";
		for(j=from ;j <= to ;  j=(j+increment))
		{
			if(selectval == j )
				string += "<option value='"+j+"' selected>"+j+"</option>"
			else
				string += "<option value='"+j+"'>"+j+"</option>"
		}
		return string;
	}


<%#operatorsarray%>
<%#fieldsarray%>

var defaultdiv = "";
var Valuediv = "<input id='valueinput' type='text' class='input1'>";
var Resourcediv = "<input id='valueinput' type='hidden'> &nbsp; <input type=button name='btnopenresource' value='' style='height:15;width:15' onclick='javascript:openresourcewindow()'>";
var DateTimediv = "<input id='valueinput' type='hidden'> &nbsp;";
date = new Date();
DateTimediv += "<SELECT id='month' class='select1'>";
DateTimediv += GetLoopValue(1,12,1,(date.getMonth() + 1));
DateTimediv += "</SELECT> &nbsp;"
DateTimediv += "<SELECT id='day' class='select1'>";
DateTimediv += GetLoopValue(1,31,1,date.getDate());
DateTimediv += "</SELECT> &nbsp;"
DateTimediv += "<SELECT id='year' class='select1'>";
DateTimediv += GetLoopValue(2003,(2003+100),1,date.getFullYear());
DateTimediv += "</SELECT> &nbsp;"
<%#valuedropdown%>

var i=0;
var oexprstr;
var sExpression="<%#querybuildervalue%>";
var sDispExpression="<%#displayquerybuildervaluehidden%>";
var iOpenBrackets=0;

var undoExpression;
var undoDispExpression;
var undoOpenBrackets;
function Button1_onclick()
{
	var retval=false;

			var oselquery = document.getElementsByTagName("select")["selquery"];
			var selqueryvalues = oselquery.value.split(",");

			if( selqueryvalues[0] == "(" )
			{
				set_undovalues();
				sExpression += "(";
				sDispExpression += "(";
				iOpenBrackets++;
			}
			else
			{
				var oseloperator = document.getElementsByTagName("select")["seloperator"];
				var oselvalue = document.getElementsByTagName("select")["selvalue"];
				if(oseloperator.value == "" || ((oselvalue.value.split("#"))[0])=="" || ((oselvalue.value.split("#"))[0])=="defaultdiv")
				{
					alert('Invalid selection.');
					return false;
				}
				//For IE 5.5 compatibility
				//var o = document.getElementsByTagName("*")["valueinput"];
				if(typeof(document.getElementsByTagName("input")["valueinput"]) != 'undefined')
					var o = document.getElementsByTagName("input")["valueinput"];
				else if(typeof(document.getElementsByTagName("select")["valueinput"]) != 'undefined')
					var o = document.getElementsByTagName("select")["valueinput"];
				else
					var o = document.getElementsByTagName("*")["valueinput"];
				if(((oselvalue.value.split("#"))[0]) == "DateTimediv")
				{
					if(!ValidateDateStr(document.getElementsByTagName("*")["day"].value +"/"+  document.getElementsByTagName("*")["month"].value  +"/"+ document.getElementsByTagName("*")["year"].value))
					{
						alert('Please select a valid Date');
						return false;
					}
					else
					{
						o.value = "Value."+ document.getElementsByTagName("*")["month"].value +"/"+ document.getElementsByTagName("*")["day"].value +"/"+ document.getElementsByTagName("*")["year"].value
					}
				}
				var oselcondition = document.getElementsByTagName("select")["selcondition"];
				if(trim(o.value) == "" || typeof(o.value) == 'undefined')
				{
					alert('Invalid value.');
					return false;
				}
				//If question mark is entered , other values should not co-exist with the ?.
				if(trim(o.value).indexOf("?") >= 0 && trim(o.value) != "?")
				{
					alert('Invalid value.');
					return false;
				}
				var endcond=false;

				if( oselcondition.value.substring(0,1) == ")" ) //Incase no open brackets pending dont allow to close the bracket
					if( iOpenBrackets <= 0 )
						return retval;
					else
						iOpenBrackets--;


				if( oselcondition.value == "End" )
					endcond=true;

				set_undovalues();
				sExpression += "["; sDispExpression += "[";
				sExpression += selqueryvalues[0]; sDispExpression += oselquery.options[oselquery.selectedIndex].text;
				sExpression += "]"; sDispExpression += "]";
				sExpression += oseloperator.value; sDispExpression += oseloperator.value;
				sExpression += "["; sDispExpression += "[";
				if( ((oselvalue.value.split("#"))[0]) != "Valuediv" )
				{
					//If resource div is selecetd then load the valeus from resource hidden fields
					if(((oselvalue.value.split("#"))[0]) == "Resourcediv")
					{
						sExpression += '"'+ document.getElementsByTagName("input")["ResourcesExpression"].value +'"';
						sDispExpression += '"'+ document.getElementsByTagName("input")["ResourcesDispExpression"].value +'"';
					}
					else
					{
						if(typeof(((o.value.split(","))[1])) == 'undefined')
						{
							sExpression += ((o.value.split(","))[0]);
						}
						else
						{
							sExpression += ((o.value.split(","))[1]);
						}
						sDispExpression += '"'+ ((o.value.split(","))[0]) +'"';
					}
				}
				else
				{

				 	//Checking for dynamic input
				 	if(o.value == "?")
				 		sExpression += '"'+selqueryvalues[0] +'.'+trim(o.value)+'"';
				 	else
				 		sExpression += "Value."+ trim(o.value) ;

					sDispExpression += '"'+trim(o.value)+'"';
				}

				sExpression += "]"; sDispExpression += "]";

				if( !endcond )
				{
					sExpression += " "+oselcondition.value;
					sDispExpression += " "+oselcondition.value;
				}
				else
				{
					while( iOpenBrackets > 0)
					{
						sExpression += ")"; sDispExpression += ")";
						iOpenBrackets--;
					}
					document.getElementsByTagName("input")["Button1"].disabled=true; //Disable Add button
					document.getElementsByTagName("input")["btnSaveSet"].disabled=false;
					document.getElementsByTagName("input")["btnSearch"].disabled=false;

				}
			}
			show_expression(sDispExpression);
			return retval;
}
	function show_expression(expression)
		{
			if( !oexprstr )
				get_framediv();
			if(typeof(expression) != 'undefined')
			{
				expression = expression.replace("Value.","").replace("Row.","").replace("Resource.^","").replace("^","");
				oexprstr.innerHTML = expression;
				document.getElementsByTagName("input")["querybuildervaluehidden"].value =  sExpression;
				document.getElementsByTagName("input")["displayquerybuildervaluehidden"].value =  expression;
			}

		}
	function SetQueryBuilderValue()
	{
		var StrValue="";
		StrValue = document.getElementsByTagName("input")["displayquerybuildervaluehidden"].value;
		if(StrValue != "")
		{
			if( !oexprstr )
				get_framediv();
			oexprstr.innerHTML = StrValue;
		}
	}
	function set_undovalues()
	{
		undoExpression = sExpression;
		undoDispExpression = sDispExpression;
		undoOpenBrackets = iOpenBrackets;
		document.getElementsByTagName("input")["undo"].disabled=false;
	}
	function get_framediv()
	{
		var framedoc;
		var frameobj;

		if(navigator.userAgent.indexOf("Netscape") >0 )
		{
			document.all = document.getElementsByTagName("iframe");
			frameobj = document.all["expr"];
			oexprstr= document.all["exprstr"];
			//framedoc = frameobj.contentDocument.getElementsByTagName("*");
			//oexprstr = framedoc["exprstr"];
		}
		else
		{
			frameobj = document.frames["expr"];
			oexprstr = document.all["exprstr"];
		}

	}
	function init()
	{
		document.getElementsByTagName("input")["undo"].disabled=true;
		if( sExpression != "" )
		{
			document.getElementsByTagName("input")["Button1"].disabled=true; //Disable Add button
			if(sDispExpression =="")
				document.getElementsByTagName("input")["btnSaveSet"].disabled=true;
		}
		else
		{
			document.getElementsByTagName("input")["Button1"].disabled=false; //Enable Add button
			document.getElementsByTagName("input")["btnSaveSet"].disabled=true;
			document.getElementsByTagName("input")["btnSearch"].disabled=true;

		}
		show_expression(sDispExpression);
	}
	function Button2_onclick()
	{
		sExpression="";
		sDispExpression="";
		iOpenBrackets=0;
		if(typeof(document.getElementsByTagName("input")["valueinput"]) != "undefined")
			document.getElementsByTagName("input")["valueinput"].value =""
		document.getElementsByTagName("input")["ResourcesExpression"].value =""
		document.getElementsByTagName("input")["ResourcesDispExpression"].value =""
		document.getElementsByTagName("input")["Button1"].disabled=false; //Enable Add button
		document.getElementsByTagName("input")["btnSaveSet"].disabled=true;
		document.getElementsByTagName("input")["btnSearch"].disabled=true;
		show_expression(sDispExpression);
	}
	function undo_onclick()
	{
		sExpression = undoExpression;
		sDispExpression = undoDispExpression;
		iOpenBrackets = undoOpenBrackets;
		document.getElementsByTagName("input")["undo"].disabled=true; //Disable undo button
		document.getElementsByTagName("input")["Button1"].disabled=false; //Enable Add button
		document.getElementsByTagName("input")["btnSaveSet"].disabled=true;
		document.getElementsByTagName("input")["btnSearch"].disabled=true;
		show_expression(sDispExpression);
	}

	function openresourcewindow()
	{

		Urlval = "?display=resourcefilter&application=<%#applicationname%>&workflow=<%#workflowname%>&DisplayType=resourcesearchfilter&datecorrectionfactor=<%#datecorrectionfactor%>"
		window.open(Urlval,"ResourceFilter","height=300,width=650,resizable=yes")
	}
	function SetName()
	{

		newurl = "?DisplayType=saveactivityset&application=<%#applicationname%>&workflow=<%#workflowname%>&datecorrectionfactor=<%#datecorrectionfactor%>&querybuildervalue="+ document.getElementsByTagName("input")["querybuildervaluehidden"].value;
		window.open(newurl,"SaveActivitySet","height=300,width=650,resizable=yes")
	}
	function SetDynamicValues()
		{
			queryval = document.getElementsByTagName("input")["querybuildervaluehidden"].value;
			queryval = trim(queryval);
			if(queryval == "")
			{
				alert('Invalid search.')
				return false;
			}
			else
			{
				return true;
			}
	}
	function SetActivitySet(value,objform)
	{
		if(value == 0)
		{
			alert('Please select a valid value.');
		}
		else
		{
			if(value == -1)
			{
				newurl = "?DisplayType=deleteactivityset&application=<%#applicationname%>&workflow=<%#workflowname%>&datecorrectionfactor=<%#datecorrectionfactor%>";
				window.open(newurl,"DeleteActivitySet","height=300,width=650,resizable=yes")

			}
			else
			{
				objform.submit();
			}
		}
	}

	//call function to show to querybuilder value after submission
	SetQueryBuilderValue();
	init();
	document.getElementsByTagName("input")["datecorrectionfactor"].value  = GetUTCOffSet()
</script>